import { Dimension, DimensionAttr } from '../basic/dimension';
export enum DimEnum {
  DimFist = 'dimFist',
  DimSec = 'dimSec',
}
export class DimManager {
  private static instance: DimManager;
  private dimGroup: { [key in DimEnum]?: Dimension } = {};
  static getInstance(): DimManager {
    if (!this.instance) {
      this.instance = new DimManager();
    }
    return this.instance;
  }
  createUpate(attrs?: DimensionAttr, key = DimEnum.DimFist) {
    if (!this.dimGroup[key]) {
      this.dimGroup[key] = new Dimension(attrs);
    } else {
      this.dimGroup[key]?.update(attrs);
    }
  }
  getCenter(key = DimEnum.DimFist) {
    return this.dimGroup[key]?.getCenter();
  }
  clear() {
    for (const key in this.dimGroup) {
      this.dimGroup[key].clear();
    }
    this.dimGroup = {};
  }
}

export const dimManager = () => {
  return DimManager.getInstance();
};
